//24 - 两两交换相邻的节点
class Solution {
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        ListNode cur = head;//第一个节点
        ListNode curNext = head.next;//第二个节点
        cur.next = swapPairs(curNext.next);//得到交换过后第二个节点指向的下一个节点
        curNext.next = cur;//两个节点互换
        return curNext;//返回交换过后第二个节点指向的下一个节点
    }
}
class Solution {
    public ListNode swapPairs(ListNode head) {
        ListNode nH = new ListNode();
        nH.next = head;
        ListNode tmp = nH;
        while(tmp.next != null && tmp.next.next != null){
            ListNode start = tmp.next;
            ListNode end = tmp.next.next;
            tmp.next = end;
            start.next = end.next;
            end.next = start;
            tmp = start;
        }
        return nH.next;
    }
}
public class swapList {
}
